<?php

class logger 
{
const EMERG   = 'EMERG';
const ALERT    = 'ALERT';
const CRIT      = 'CRIT';
const ERR       = 'ERR';
const WARN    = 'WARN';
const NOTICE  = 'NOTIC';
const INFO     = 'INFO';
const DEBUG   = 'DEBUG';
const SQL       = 'SQL';
const SYSTEM = 0;
const MAIL      = 1;
const TCP       = 2;
const FILE       = 3;
static $log =   array();
static $format =  '[ c ]';
static function record($message,$level=self::ERR,$record=false) {
if($record ||in_array($level,array('EMERG','ALERT','CRIT','ERR'))) {
$now = date(self::$format);
self::$log[] =   "{$now} {$level}: {$message}\r\n";
}
}
static function save($type=self::FILE,$destination='',$extra='')
{
if(empty($destination))
{
if(!is_dir( APP_ROOT_PATH.'public/logger/'))
{
if(!mkdir(APP_ROOT_PATH.'public/logger/'))
{
return false;
}
}
$destination = APP_ROOT_PATH.'public/logger/'.date('y_m_d').'.logger';
}
if(self::FILE == $type) {
if(is_file($destination) &&floor(2000000) <= filesize($destination) )
rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
}
error_log(implode('',self::$log),$type,$destination ,$extra);
self::$log = array();
}
static function write($message,$level=self::ERR,$type=self::FILE,$destination='',$extra='')
{
$now = date(self::$format);
if(empty($destination))
$destination = LOG_PATH.date('y_m_d').'.logger';
if(self::FILE == $type) {
if(is_file($destination) &&floor(2000000) <= filesize($destination) )
rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
}
error_log("{$now} {$level}: {$message}\r\n",$type,$destination,$extra );
}
}

?>